#include<iostream>
#include<cstdio>
#include<queue>
#define int long long
using namespace std;
const int Max = 100005;
struct node
{
	int t;
	int v;
};
deque<node>q;
int a[Max];
int f[Max];
signed main()
{
	int n,k;
	cin >> n >> k;
	int tot = 0;
	for(register int i = 1;i <= n;++ i)
		cin >> a[i],tot += a[i];
	int M = 0x7f7f7f7f7f7f;
	q.push_back((node){0,0});
	for(register int i = 1;i <= n;++ i)
	{
		while(!q.empty() && i - q.front().t > k + 1)
			q.pop_front();
		f[i] = q.front().v + a[i];
		while(!q.empty() && f[i] < q.back().v)
			q.pop_back();
		q.push_back((node){i,f[i]});
	}
    for(int i = n - k;i <= n;i++)
    {
        
    }
	for(register int i = n;i >= n - k;i --)
		M = min(M,f[i]);
	cout << tot - M << endl;
	return 0;
}